package com.atlzk.group.order.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atlzk.group.order.entity.GroupEntity;
import com.atlzk.group.order.service.GroupService;
import com.atlzk.common.utils.PageUtils;
import com.atlzk.common.utils.R;


/**
 * 用户拼团表
 *
 * @author liuzekun
 * @email 2803587841@gmail.com
 * @date 2021-06-18 17:11:50
 */
@RestController
@RequestMapping("order/group")
@CrossOrigin
public class GroupController {
    @Autowired
    private GroupService groupService;

    /**
     * 列表
     */
    @RequestMapping("/list/{smsTgouId}")
    //@RequiresPermissions("order:group:list")
    public R list(@RequestParam Map <String, Object> params,@PathVariable("smsTgouId") Long smsTgouId) {
        PageUtils page = groupService.queryPage(params,smsTgouId);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("order:group:list")
    public R list(@RequestParam Map <String, Object> params) {
        PageUtils page = groupService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{omsGroupId}")
    //@RequiresPermissions("order:group:info")
    public R info(@PathVariable("omsGroupId") Long omsGroupId) {
        GroupEntity group = groupService.getById(omsGroupId);

        return R.ok().put("group", group);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:group:save")
    public R save(@RequestBody GroupEntity group) {

        groupService.save(group);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:group:update")
    public R update(@RequestBody GroupEntity group) {
        groupService.updateById(group);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:group:delete")
    public R delete(@RequestBody Long[] omsGroupIds) {
        groupService.removeByIds(Arrays.asList(omsGroupIds));

        return R.ok();
    }

    /**
     * 开团
     */
    @RequestMapping("/openGroup/{umsUserId}")
    //对象内long类型无法接到  用户id
    public R openGroup(@RequestBody GroupEntity groupEntity, @PathVariable String umsUserId) {
        groupEntity.setUmsUserId(Long.valueOf(umsUserId));
        groupService.openGroup(groupEntity);
        return R.ok();
    }




}
